home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / pdselect / blizkick / modules / blizkickmodule.i < prev    next >
Text File  |  2000-02-16  |  8KB  |  304 lines

  1.     IFND    BLIZKICKMODULE_I
  2. BLIZKICKMODULE_I    SET    1
  3. **
  4. **    $VER: blizkickmodule.i 1.5 (3.2.2000)
  5. **    Includes Release 1.5
  6. **
  7. **    Macros and defines for BlizKick's "modules" and "patches".
  8. **
  9. **    (C) Copyright 1996-2000 PitPlane Productions.
  10. **        All Rights Reserved
  11. **
  12.  
  13.     IFND EXEC_TYPES_I
  14.     INCLUDE "exec/types.i"
  15.     ENDC ; EXEC_TYPES_I
  16.  
  17.     IFND EXEC_NODES_I
  18.     INCLUDE "exec/nodes.i"
  19.     ENDC ; EXEC_NODES_I
  20.  
  21.     IFND EXEC_RESIDENT_I
  22.     INCLUDE "exec/resident.i"
  23.     ENDC ; EXEC_RESIDENT_I
  24.  
  25.     IFGT    0
  26.  
  27.    "Modules" are executable files that are loaded with LoadSeg(). Only the
  28.  first segment can be used and the code *MUST* be PC-relative. Modules contain
  29.  a LONG id and Resident Tag. This resident tag will be added to KS ROM. There
  30.  are two macros defined in this file (BK_MOD and BK_MODA), which can be used
  31.  (=should be used) to create "Modules".
  32.  
  33.    "Module" can (from BlizKick V1.6 on) also be a patch, in which case macro
  34.  called BK_PTC should be used to create it. See macro definition below for
  35.  detailed information. Note that "patch" needn't be fully PC-relative (the
  36.  patching code can be relocatable, it is loaded with LoadSeg() after all).
  37.  
  38.  
  39.  bkm_Flags
  40.  ~~~~~~~~~
  41.  Normally modules can be installed multiple times, but if bkm_Flags has
  42.  BKMB_SingleMode bit set then this module (RT_NAME and RT_PRI match) can be
  43.  found from ROM only once.
  44.  
  45.  If bkm_Flags has BKMB_ReplaceMode bit set then the ROM is scanned for Resident
  46.  Tag with same name (RT_NAME) and priority (RT_PRI) as in this "module". If
  47.  such resident is found it'll be replaced (overwritten) by module's Resident
  48.  Tag. This feature must be considered as "hackish", because resident tags don't
  49.  always be in ROM as one big chunk, but are split into thousand and one little
  50.  pieces... :-( Additionally there are usually code and data inside Resident Tag
  51.  which has nothing to do with that Tag... :.-((. So, if you'd like like to
  52.  safely(?) replace OS Resident Tags you should use this flag in conjugation
  53.  with BKMB_ExtResBuf.
  54.  
  55.  With this feature you could, for example, replace 'exec.library' resident
  56.  with better one, improve KS3.x 'alert.hook' or improve KS1.3 'bootstrap'...
  57.  It's up to you, Coders...
  58.  
  59.  If you specify BKMB_ExtResBuf flag this module will require it to be installed
  60.  to external Resident Tag buffer created by EXTRESBUF feature of the BlizKick.
  61.  Using this makes only(?) sense with BKMB_ReplaceMode...
  62.  
  63.  It was one shiny day I got up with this *great* idea of "modules". Kickstart
  64.  MapROM tools will never be the same again... ;-)
  65.  
  66.     ENDC
  67.  
  68.  
  69. BKMODULE_ID    EQU    $707A4E75    ; moveq #'z',d0; rts
  70. BKEP_ID        EQU    $4E71        ; nop ;-)
  71.  
  72. ERH_API_V1    EQU    1
  73.  
  74.     ; bkm_Flags:
  75.  
  76.     BITDEF    BKM,ReplaceMode,0    ; Turn on REPLACE MODE
  77.     BITDEF    BKM,SingleMode,1    ; Do *not* allow same "module" multiple times
  78.     BITDEF    BKM,ExtResBuf,2        ; Require EXTRESBUF for this module
  79. BKMF_ALL EQU    BKMF_ReplaceMode!BKMF_SingleMode!BKMF_ExtResBuf
  80.  
  81.     STRUCTURE bkmodule,0
  82.     ULONG    bkm_ID            ; Must be BKMODULE_ID
  83.     UWORD    bkm_Flags        ; See above
  84.     STRUCT    bkm_ResTag,RT_SIZE    ; Resident Tag (not relocated!)
  85. ;;    LABEL    bkmodule_SIZEOF        ; There's no SIZEOF!
  86.  
  87.  
  88. ;
  89. ; BK_MOD -- Create a simple ResidentTag without AUTOINIT
  90. ;
  91. ; mflags   - "Module" flags, see above.
  92. ; end      - ptr to end of this ResidentTag
  93. ; flags    - ResidentTag flags
  94. ; reqver   - required KS version for this module. This is *NOT*
  95. ;         the ResidentTag version, but required version to use this
  96. ;         module. ResidentTag version will be forced to current
  97. ;         ROM version.
  98. ; type     - type of module (NT_XXXXXX)
  99. ; pri      - priority for this ResidentTag
  100. ; name     - ptr to name of this ResidentTag
  101. ; idstring - ptr to idstring of this ResidentTag
  102. ; init     - ptr to init code
  103.  
  104. ; no-autoinit-module:
  105. BK_MOD    MACRO    *mflags,end,flags<<24+reqver<<16+type<<8+pri,name,idstring,init
  106.     IFGT    NARG-6
  107.     FAIL    !!!! TOO MANY ARGUMENTS TO BK_MOD !!!!
  108.     MEXIT
  109.     ELSE
  110.     IFGT    6-NARG
  111.     FAIL    !!!! TOO FEW ARGUMENTS TO BK_MOD !!!!
  112.     MEXIT
  113.     ENDC
  114.     ENDC
  115.     dc.l    BKMODULE_ID
  116.     dc.w    \1
  117. .mod\@    dc.w    RTC_MATCHWORD
  118.     dc.l    0
  119.     dc.l    ((\2)-.mod\@+1)
  120.     dc.l    (\3)&~(RTF_AUTOINIT<<24)
  121.     dc.l    (\4)-.mod\@
  122.     dc.l    (\5)-.mod\@
  123.     dc.l    (\6)-.mod\@
  124.     ENDM
  125.  
  126.  
  127. ;
  128. ; BK_MODA -- Create a complex ResidentTag with AUTOINIT (library/device/resource?)
  129. ;
  130. ; mflags   - "Module" flags, see above.
  131. ; end      - ptr to end of this ResidentTag
  132. ; flags    - ResidentTag flags
  133. ; reqver   - required KS version for this module. This is *NOT*
  134. ;         the ResidentTag version, but required version to use this
  135. ;         module. ResidentTag version will be forced to current
  136. ;         ROM version.
  137. ; type     - type of module (NT_XXXXXX)
  138. ; pri      - priority for this ResidentTag
  139. ; name     - ptr to name of this ResidentTag
  140. ; idstring - ptr to idstring of this ResidentTag
  141. ; size     - see exec.library/InitResident
  142. ; funcs    - see exec.library/InitResident
  143. ; initstruct - see exec.library/InitResident
  144. ; initfunc - see exec.library/InitResident
  145.  
  146. ; autoinit-module:
  147. BK_MODA    MACRO    *mflags,end,flags<<24+reqver<<16+type<<8+pri,name,idstring,size,funcs,initstruct,initfunc
  148.     IFGT    NARG-9
  149.     FAIL    !!!! TOO MANY ARGUMENTS TO BK_MODA !!!!
  150.     MEXIT
  151.     ELSE
  152.     IFGT    9-NARG
  153.     FAIL    !!!! TOO FEW ARGUMENTS TO BK_MODA !!!!
  154.     MEXIT
  155.     ENDC
  156.     ENDC
  157.     dc.l    BKMODULE_ID
  158.     dc.w    \1
  159. .mod\@    dc.w    RTC_MATCHWORD
  160.     dc.l    0
  161.     dc.l    ((\2)-.mod\@+1)
  162.     dc.l    (\3)!(RTF_AUTOINIT<<24)
  163.     dc.l    (\4)-.mod\@
  164.     dc.l    (\5)-.mod\@
  165.     dc.l    .mod2\@-.mod\@
  166. .mod2\@    dc.l    \6
  167.     dc.l    (\7)-.mod\@
  168.     dc.l    (\8)-.mod\@
  169.     dc.l    (\9)-.mod\@
  170.     ENDM
  171.  
  172.  
  173. ;
  174. ; BK_PTC -- Create a header for BlizKick external patch
  175. ;
  176. ;   Notes
  177. ;   ~~~~~
  178. ; Code is run with following incoming parameters:
  179. ;
  180. ; a0=ptr to ROM start (buffer)    eg. $1DE087B8
  181. ; a1=ptr to ROM start (ROM)    eg. $00F80000 (do *not* access!)
  182. ; d0=ROM lenght in bytes    eg. $00080000
  183. ; a2=ptr to _FindResident routine (will search ROM buffer for resident tag):
  184. ;    CALL: jsr (a2)
  185. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to resident name
  186. ;     OUT: d0=ptr to resident (buf) or NULL
  187. ; a3=ptr to _InstallModule routine (can be used to plant a "module"):
  188. ;    CALL: jsr (a3)
  189. ;      IN: a0=ptr to ROM, d0=rom len, a1=ptr to module, d6=dosbase
  190. ;     OUT: d0=success
  191. ; a4=ptr to _Printf routine (will dump some silly things (errormsg?) to stdout ;-)
  192. ;    CALL: jsr (a4)
  193. ;      IN: a0=FmtString, a1=Array (may be 0), d6=dosbase
  194. ;     OUT: -
  195. ; d6=dosbase, a6=execbase
  196. ;
  197. ; Code should return:
  198. ;
  199. ; d0=true if succeeded, false if failed.
  200. ; d1-d7/a0-a6 can be trashed. a7 *must* be preserved! ;-)
  201. ;
  202. ; Code doesn't need to worry about cache flushing after it has done its
  203. ; modifications. If the patch code requires some new KS (3.x) features
  204. ; you *must* test for approriate KS version!! If patch code is run you
  205. ; can assume that you're running on at least AmigaOS 2.0 (V36). Note the
  206. ; difference between os version you're running atm and os version user
  207. ; is going to boot.
  208. ;
  209. ; Please, be as fast as possible because user might want to add *several*
  210. ; patches! Also note that _Printf output is supressed if user specifies
  211. ; QUIET switch.
  212. ;
  213. ; The macro is used like this:
  214. ;
  215. ;    SECTION    PATCH,CODE
  216. ;
  217. ;_SEGSTART_DUMMY:
  218. ;
  219. ;    BK_PTC
  220. ;
  221. ;patchcode:
  222. ;    cmp.w    #37,($C,A0)    ; This patch requires V37 ROM (KS 2.04) or better...
  223. ;    blo.b    .fail
  224. ;
  225. ;    subq.l    #6,d0        ; don't test past end
  226. ;    move.l    #$xxxxxxxx,d1    ; Search for (xxxxxxxx,yyyyyyyy,zzzzzzzz):
  227. ;.find;    addq.l    #2,a0
  228. ;    subq.l    #2,d0
  229. ;    beq.b    .fail
  230. ;    cmp.l    (a0),d1
  231. ;    bne.b    .find
  232. ;    cmp.l    #$yyyyyyyy,(4,a0)
  233. ;    bne.b    .find
  234. ;    cmp.l    #$zzzzzzzz,(8,a0)
  235. ;    bne.b    .find
  236. ;    bra.b    .found
  237. ;
  238. ;.fail    moveq    #0,d0
  239. ;    rts
  240. ;
  241. ;.found    movem.l    d2-d7/a2-a6,-(sp)
  242. ;
  243. ;    do the patching...
  244. ;    ...etc...
  245. ;
  246. ;    movem.l    (sp)+,d2-d7/a2-a6
  247. ;    moveq    #1,d0
  248. ;    rts
  249. ;
  250.  
  251. ; external patch:
  252. BK_PTC    MACRO
  253.     IFGT    NARG
  254.     FAIL    !!!! BK_PTC DOES NOT TAKE ANY ARGUMENTS !!!!
  255.     MEXIT
  256.     ENDC
  257.     dc.l    BKMODULE_ID
  258.     dc.w    0,BKEP_ID
  259.     ENDM
  260.  
  261.  
  262. ; Following macros can be used to create function tables for devices, libraries
  263. ; and resources:
  264.  
  265. BK_INITFUNCS    MACRO    *label
  266.     IFGT    NARG-1
  267.     FAIL    !!!! TOO MANY ARGUMENTS TO BK_INITFUNCS !!!!
  268.     MEXIT
  269.     ELSE
  270.     IFGT    1-NARG
  271.     FAIL    !!!! TOO FEW ARGUMENTS TO BK_INITFUNCS !!!!
  272.     MEXIT
  273.     ENDC
  274.     ENDC
  275.     CNOP    0,2
  276. \1
  277. _BKM_FB_GLOBAL\@
  278.     dc.w    -1
  279. .BKM_FUNCBASE    EQU    *-2
  280.     ENDM
  281.  
  282. BK_FUNC    MACRO    *funclabel
  283.     IFGT    NARG-1
  284.     FAIL    !!!! TOO MANY ARGUMENTS TO BK_FUNC !!!!
  285.     MEXIT
  286.     ELSE
  287.     IFGT    1-NARG
  288.     FAIL    !!!! TOO FEW ARGUMENTS TO BK_FUNC !!!!
  289.     MEXIT
  290.     ENDC
  291.     ENDC
  292.     dc.w    (\1)-.BKM_FUNCBASE
  293.     ENDM
  294.  
  295. BK_ENDFUNCS    MACRO
  296.     IFGT    NARG
  297.     FAIL    !!!! BK_ENDFUNCS DOES NOT TAKE ANY ARGUMENTS !!!!
  298.     MEXIT
  299.     ENDC
  300.     dc.w    -1
  301.     ENDM
  302.  
  303.     ENDC    ; BLIZKICKMODULE_I
  304.